using UnityEngine;
using System.Collections;

public class MouseReplace : MonoBehaviour
{
	
	public Transform mouse;
	public SWFPlayer uiMouse;
	public PlayerAction playerAction;
	InputInfo inputInfo;
	Vector3 mouseLocation;
	//ClipAnimation clipAnimation;

	// Use this for initialization
	void Start ()
	{
		if (!mouse)
			return;
		
		if (playerAction == null)
			playerAction = PlayerData.Instance ().MainRoleInstance.GetComponent<PlayerAction> ();
		
		inputInfo = Camera.main.GetComponent<InputInfo> ();
		
		mouseLocation = mouse.position;
	}
	
	// Update is called once per frame
	void Update ()
	{
		if (inputInfo.hasSingleTouch) {
			mouse.gameObject.SetActive (true);
			mouseLocation.x = inputInfo.Hit.point.x;
			mouseLocation.y = inputInfo.Hit.point.y;
		}
		/*
		else if (inputInfo.TouchingUI) {
			Vector3 effectPosition = Vector3.zero;
			effectPosition.x = inputInfo.Hit.point.x;
			effectPosition.y = inputInfo.Hit.point.y;
			uiMouse.transform.localPosition = effectPosition;
			uiMouse.Play();
		}*/ 
		else {
			if (playerAction.IsIdling) {
				mouse.gameObject.SetActive (false);
			}
		}
		
		mouse.position = mouseLocation;
	}

	public void setMousePos (Vector3 pos)
	{
		mouse.gameObject.SetActive (true);
		mouseLocation.x = pos.x;
		mouseLocation.y = pos.y;
		mouse.position = mouseLocation;
	}
}
